/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pubguru.data;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author Dao
 */
public class CiteSeerIntegration extends Integration{
    public CiteSeerIntegration(String _paperFile,String _authorFile, String _paper_authorFile)
    {
        super();
        paperFile = _paperFile;
        authorFile = _authorFile;
        paper_authorFile = _paper_authorFile;
    }
    
    @Override
    public void Run() 
    {
        try{
            FileReader fr = new FileReader(paperFile);
            BufferedReader br = new BufferedReader(fr);
            br.readLine(); //ignore first line
            String str="";
            String[] tokens;
            String paperName;
            int paperYear;
            int count = 0;
            int count2 = 0;
            String standardPaperName = "";
            while ((str = br.readLine()) != null)
            {
                count++;
                tokens = str.split("\t");
                if (tokens.length >= 2)
                {
                    paperName = tokens[1];
                    paperYear = 0;
                    if (tokens.length == 3)
                    {
                        try
                        {
                            paperYear = Integer.parseInt(tokens[2]);
                        }catch (Exception e)
                        {
                            paperName += tokens[2];
                            if (tokens.length == 4)
                                paperYear = Integer.parseInt(tokens[3]);
                        }
                    }
                    standardPaperName = paperName.replace(",", "").replace(".","").replace("/","").replace("?","").replace(":", "").replace("!","").replace("\\", "").replace("'", "").replace("-", "").replace(":", "").replace("\\", "").toLowerCase().replaceAll("\\s+", "");
                    PaperData.getInstance().AddPaper(standardPaperName, paperYear);
                }
                else
                {
                     count2++;
                }
            }
            br.close();
            fr.close();
            System.out.println("Total publications in CiteSeer : " + count);
            System.out.println("Total publications missing information in CiteSeer : " + count2);
            totalPaperMissingInfor = count2;
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }
}
